local skel = fk.CreateSkill{
  name = "tea__tonglun",
}
--local U = require "packages/utility/utility"
Fk:loadTranslationTable{
  ["tea__tonglun"] = "同纶",
  [":tea__tonglun"] = "准备阶段，你可以令任意名角色选择摸或弃置一张牌，然后若手牌数与你相同的角色因此变多，你可以重复此流程。",
  ["#tea__tonglun-invoke"] = "同纶：选择任意名角色，其同时选择摸或弃置一张牌",
  ["#tea__tonglun-choose"] = "同纶：直接确定或取消选择摸一张牌，或选择一张牌弃置",
}
---@type TrigSkelSpec<PhaseFunc>
local tonglun = {
  can_trigger = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = room:askToChoosePlayers(player, {
      targets = room:getAlivePlayers(),
      skill_name = skel.name,
      min_num = 1,
      max_num = 999,
      prompt = "#tea__tonglun-invoke",
    })
    if #targets > 0 then
      event:setCostData(self, { tos = targets })
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local tos = event:getCostData(self).tos
    local getPlayersFunc = function ()
      local num = #player:getCardIds("h")
      return #table.filter(room:getAlivePlayers(), function(p)
        return #p:getCardIds("h") == num
      end)
    end
    local record_num = 0
    while getPlayersFunc() > record_num do
      if player.dead then break end
      if record_num ~= 0 then
        tos = room:askToChoosePlayers(player, {
          targets = room:getAlivePlayers(),
          skill_name = skel.name,
          min_num = 1,
          max_num = 999,
          prompt = "#tea__tonglun-invoke",
        })
      end
      record_num = getPlayersFunc()
      room:sortByAction(tos)
      local result = room:askToJointCards(player, {
        players = tos,
        min_num = 0,
        max_num = 1,
        skill_name = skel.name,
        will_throw = true,
        include_equip = true,
        prompt = "#tea__tonglun-choose"
      })
      for p, cids in pairs(result) do
        room:delay(200)
        if p.dead then break end
        if #cids == 0 then
          p:drawCards(1, skel.name)
        elseif #cids == 1 then
          room:throwCard(cids, skel.name, p, p)
        end
      end
    end
  end
}
skel:addEffect(fk.EventPhaseStart, tonglun)
-- Fk.generals["mouxusheng"]:addSkill(skel.name)
return skel